using BLToolkit.Data;
using BLToolkit.DataAccess;

using TrueCode.DependencyManager;

namespace EMan.Server.DependencyInjection
{
  public class InstantiateAccessor : IFilteringInstantiate
  {
    public void Execute( IBuildSession context )
    {
      if( typeof( DataAccessor ).IsAssignableFrom( context.SessionAim.Type ) )
      {
        var newBuildSession = context.MakeCopy( typeof( DbManager ) );
        context.Instance = DataAccessor.CreateInstance( context.SessionAim.Type, ( DbManager )newBuildSession.Build(), false );
      }
      context.ExecuteNextBuildAction();
    }
  }
}